package src.shop.playhan.ui.components.button 
{
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;	

	public class ToggleButton extends BasicButton 
	{
		public var FRAME_ICON_ON : * ;
		public var FRAME_ICON_OFF : *;
		
		protected var _selected : Boolean;
		
		protected var _icon : DisplayObject;

		
		public function ToggleButton(view : DisplayObject = null, frameUp : * = 1, frameOver : * = 2, frameDown : * = 3, frameDisable : * = 4, frameIconOn : * = 1, frameIconOff : * = 2) 
		{			
			super(view, frameUp, frameOver, frameDown, frameDisable);
			
			FRAME_ICON_ON = frameIconOn;
			FRAME_ICON_OFF = frameIconOff;
			
			_icon = view["icon"];		
		}
		
		public function setSelected(selected : Boolean) : void 
		{			
			_selected = selected;
			if (_view is Sprite) _view["buttonMode"] = !_selected;
			if (_icon != null && icon is MovieClip) MovieClip(_icon).gotoAndStop(_selected ? FRAME_ICON_ON : FRAME_ICON_OFF);
		}
		
		public function toggled() : void
		{
			setSelected(!selected);
		}
		
		public function get selected() : Boolean
		{
			return _selected;
		}
		
		public function set selected(selected : Boolean) : void
		{
			_selected = selected;
		}
		
		public function get icon() : DisplayObject
		{
			return _icon;
		}
		
		public function set icon(icon : DisplayObject) : void
		{
			_icon = icon;
		}		
	} // end class
} // end package